﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;

namespace DataProcess {
	class ListBoxTraceListener : TraceListener {
		private ListBox _control;
		public ListBoxTraceListener(ListBox target) {
			_control = target;
		}

		public override void Write(string message) {
			if (_control.Items.Count > 0) {
				_control.Items[_control.Items.Count - 1] += message;
			}
			else {
				_control.Items.Add(message);
			}
			_control.SelectedIndex = _control.Items.Count - 1;
		}

		public override void WriteLine(string message) {
			_control.Items.Add(message);
			_control.SelectedIndex = _control.Items.Count - 1;
		}
	}
}
